export class RandomLocator {
    private ic: Array<number>

    public init(size: number): void {
        this.ic = []
        for (let i = 0; i < size; i++) {
            this.ic[i] = i
        }
    }

    private checkInit(): void {
        if (this.ic == null) {
            throw "没有初始化"
        }
    }

    public randomPop(): number {
        this.checkInit()
        if (this.ic.length === 0) {
            return -1
        }
        let i = Math.floor(Math.random() * this.ic.length)
        const res = this.ic[i];
        this.ic.splice(i, 1)
        return res
    }

    public pop(): number {
        this.checkInit()
        if (this.ic.length == 0) {
            return -1
        }
        return this.ic.shift()
    }
}